#pragma once
#include "waconsts.h"
#include "waitbox.h"
#include "datastore.h"
//#include "WaitBoxHelper.h"

struct MAP_CalcParams{
	std::vector< int> eids ;
	unsigned int startpt;
	unsigned int endpt;
	int signiture;
};

class MAPCalculator
{
	static MAPCalculator *instance;
	MAPCalculator(void);
	bool isOutputReady;
	std::vector<MAPOutput*> out;
	const DataStore *source;
	CWaitBoxDlg wbd;
	void DoCalc(const MAP_CalcParams p);//calc the fft of the n-th ch.
	friend void MAP_Working_Thread( LPVOID );
public:
	~MAPCalculator(void);
	static MAPCalculator *GetInstance(){
		if(!instance)
			instance = new MAPCalculator();
		return instance;
	}

	static void DestoryInstance(){
		if(instance)
			delete instance;
	}

	int EID2Index(int eid) const ;
//	int Index2EID(UINT index) const {if(index>=out.size()) return -1; return out[index].eid;};
	const std::vector<MAPOutput*> GetOutputs() const{return out;}
	const DataStore* GetSource() const {return source;}
	size_t GetOutputCount() const { return out.size();}
	bool StartCalc(const MAP_CalcParams p);
	bool isReady() const{ return isOutputReady;};
	void SetSource(const DataStore *s){source = s;}
	bool Export2File (LPCTSTR filename, int eid)const;
};
